<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
				xmlns:ui="http://java.sun.com/jsf/facelets"
				xmlns:h="http://java.sun.com/jsf/html"
				xmlns:a4j="http://richfaces.org/a4j"
				xmlns:rich="http://richfaces.org/rich"
				xmlns:f="http://java.sun.com/jsf/core"
				xmlns:c="http://java.sun.com/jstl/core"
				xmlns:t="http://myfaces.apache.org/tomahawk"
				template="/pages/crud_template.xhtml"> 

	<ui:param name="crudBean" value="#{usuarioBean}" />
	
	<ui:define name="requiredFieldsMessage">
		<h:outputText value="#{bundle.todosCamposObrigatorios}" rendered="#{crudBean.updating}"/>
		<h:outputText value="#{bundle.peloMenosUmDosCamposObrigatorios}" rendered="#{crudBean.searching}"/>
	</ui:define>
	
	<ui:define name="saveStateObjectsDefined">
		<t:saveState value="#{crudBean.listaEmpresas}" />
		<t:saveState value="#{crudBean.listaEstabelecimentos}" />
		<t:saveState value="#{crudBean.listaEstabelecimentosUsuario}" />
	</ui:define>
	
	<ui:define name="content">
		<!-- Painel de Pesquisa - Inicio -->
		<h:panelGroup id="panelGroupDePesquisa" rendered="#{crudBean.searching}">
			<f:subview id="viewBusca">
				<table>
					<tr>
						<td class="tdCor" width="25%"><h:outputText value="#{bundle.lbl_codigo}"/> *</td>
						<td class="tdBranco">
							<h:inputText value="#{crudBean.searchObject.codigo}" size="30" maxlength="12" onkeypress="soNumero(this)" />
						</td>
					</tr>
					<tr>
						<td class="tdCor"><h:outputText value="#{bundle.lbl_nome}"/> *</td>
						<td class="tdBranco">
							<h:inputText value="#{crudBean.searchObject.nome}" size="60" maxlength="50" onkeypress="return maiuscula(this)" />
						</td>
					</tr>
					<tr>
						<td class="tdCor"><h:outputText value="#{bundle.lbl_login}"/> *</td>
						<td class="tdBranco">
							<h:inputText value="#{crudBean.searchObject.login}" size="60" maxlength="20" onkeypress="return maiuscula(this)" />
						</td>
					</tr>
					<tr>
						<td class="tdCor" width="20%"><h:outputText value="#{bundle.lbl_empresa}"/> *</td>
						<td class="tdBranco">
							<h:selectOneMenu value="#{crudBean.searchObject.estEmpresaVo.codigo}" converter="simpleIndexConverter">
    							<t:selectItems var="o" itemValue="#{o.codigo}" itemLabel="#{o.descricao}" value="#{crudBean.listaEmpresas}" />
    						</h:selectOneMenu>
						</td>
					</tr>
					<tr>
						<td class="tdCor" width="25%"><h:outputText value="#{bundle.lbl_situacao}"/></td>
						<td class="tdBranco"> 
							<table style="width: 200px;">
								<tr>
									<td>
										<h:selectOneRadio value="#{crudBean.searchObject.flagAtivo}">
			   							   <f:selectItem itemValue="T" itemLabel="#{bundle.lbl_todos}"/>   
										   <f:selectItem itemValue="S" itemLabel="#{bundle.lbl_ativo}"/>   
										   <f:selectItem itemValue="N" itemLabel="#{bundle.lbl_inativo}"/>  
										</h:selectOneRadio>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</f:subview>
		</h:panelGroup>
		<!-- Painel de Pesquisa - Fim -->
		
		<!-- Painel de Cadastro - Inicio -->
		<h:panelGroup id="panelGroupDeCadastro" rendered="#{crudBean.updating}">
			<f:subview id="viewCadastro">
				<table>
					<tr>
						<td class="tdCor" width="20%"><h:outputText value="#{bundle.lbl_empresa}"/> *</td>
						<td class="tdBranco">
							<h:selectOneMenu rendered="#{crudBean.inserting}" value="#{crudBean.entity.estEmpresaVo.codigo}" converter="simpleIndexConverter">
    							<t:selectItems var="o" itemValue="#{o.codigo}" itemLabel="#{o.descricao}" value="#{crudBean.listaEmpresas}" />
    							<a4j:support event="onchange" reRender="panelGroupDeCadastro" actionListener="#{crudBean.setarListaEstabelecimentos}"/>
    						</h:selectOneMenu>
    						<h:outputText rendered="#{crudBean.editing}" value="#{crudBean.entity.estEmpresaVo.descricao}"/>
						</td>
					</tr>
					<tr>
						<td class="tdCor"><h:outputText value="#{bundle.lbl_nome}"/> *</td>
						<td class="tdBranco">
							<h:inputText value="#{crudBean.entity.nome}" size="60" maxlength="50" onkeypress="return maiuscula(this)" />
						</td>
					</tr>
					<tr>
						<td class="tdCor"><h:outputText value="#{bundle.lbl_login}"/> *</td>
						<td class="tdBranco">
							<h:inputText value="#{crudBean.entity.login}" size="60" maxlength="20" onkeypress="return maiuscula(this)" />
						</td>
					</tr>
					<tr>
						<td class="tdCor" width="25%"><h:outputText value="#{bundle.lbl_ativo}"/></td>
						<td class="tdBranco"> 
							<table style="width: 200px;">
								<tr>
									<td>
										<h:selectOneRadio value="#{crudBean.entity.flagAtivo}">
										   <f:selectItem itemValue="S" itemLabel="#{bundle.lbl_sim}"/>   
										   <f:selectItem itemValue="N" itemLabel="#{bundle.lbl_not}"/>  
										</h:selectOneRadio>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<br></br>
						</td>
					</tr>
					<tr>
						<td class="tdCor"><h:outputText value="#{bundle.lbl_loja}"/> *</td>
						<td class="tdBranco">
							<h:selectOneMenu value="#{crudBean.entity.filtroVo.estLojaVo.codigo}" converter="simpleIndexConverter">
	   							<t:selectItems var="o" itemValue="#{o.codigo}" itemLabel="#{o.descricao}" value="#{crudBean.listaEstabelecimentos}" />
	   						</h:selectOneMenu>
						</td>
					</tr>
				</table>
				
				<br></br>
				
				<table>
					<tr>
						<td>
							<a4j:commandButton value="#{bundle.lbl_add}" actionListener="#{crudBean.adicionarEstabelecimento}" reRender="panelGroupDeCadastro"/>
						</td>
					</tr>
				</table>
				
				<br></br>
				
				<f:subview id="viewEstabelecimentoUsuario">
					<rich:dataTable id="tblDataExtensaoUsuario" value="#{crudBean.entity.filtroVo.listaExtensaoUsuario}" binding="#{crudBean.tblDataExtensaoUsuario}" var="rst" style="width: 50%;" rowClasses="par,impar">
						
						<rich:column style="text-align: right;" sortBy="#{rst.codigo}">
							<f:facet name="header">
								<h:outputText value="#{bundle.lbl_codigo_loja}" />
							</f:facet>
							<h:outputText value="#{rst.estLojaVo.codigo}"/>
						</rich:column>
	               		<rich:column style="text-align: left;" sortBy="#{rst.descricao}">
							<f:facet name="header">
								<h:outputText value="#{bundle.lbl_loja}" />
							</f:facet>
							<h:outputText value="#{rst.estLojaVo.descricao}"/>
						</rich:column>
	               		<rich:column style="text-align: center;" sortBy="#{rst.flagAtivo}">
							<f:facet name="header">
								<h:outputText value="#{bundle.lbl_ativo}" />
							</f:facet>
							<h:outputText value="#{rst.flagAtivo}"/>
						</rich:column>
	               		<rich:column style="text-align: center;">
							<f:facet name="header">
								<h:outputText value="" />
							</f:facet>
							<a4j:commandLink actionListener="#{crudBean.excluirEstabelecimento}" rendered="#{rst.flagAtivo == 'SIM' }" ajaxSingle="true" reRender="tblDataExtensaoUsuario">
								<h:graphicImage title="cancelar" value="/imagens/inativar.bmp" style="border: 0px;"/>
							</a4j:commandLink>
						</rich:column>
					</rich:dataTable>
				</f:subview>
				
			</f:subview>
		</h:panelGroup>
		<!-- Painel de Cadastro - Fim -->

		<!-- Painel de Visualizar - Inicio -->
		<h:panelGroup id="panelGroupDeView" rendered="#{crudBean.viewing}">
			<f:subview id="viewVisualizar">
				<table>
					<tr>
						<td class="tdCor"><h:outputText value="#{bundle.lbl_empresa}"/> </td>
						<td class="tdBranco">
							<h:outputText value="#{crudBean.entity.estEmpresaVo.codigo}" />
							<h:outputText value=" - " />
							<h:outputText value="#{crudBean.entity.estEmpresaVo.descricao}" />
						</td>
					</tr>
					<tr>
						<td class="tdCor" width="25%"><h:outputText value="#{bundle.lbl_codigo}"/> </td>
						<td class="tdBranco">
							<h:outputText value="#{crudBean.entity.codigo}"/>
						</td>
					</tr>
					<tr>
						<td class="tdCor"><h:outputText value="#{bundle.lbl_nome}"/> </td>
						<td class="tdBranco">
							<h:outputText value="#{crudBean.entity.nome}" />
						</td>
					</tr>
					<tr>
						<td class="tdCor"><h:outputText value="#{bundle.lbl_login}"/> </td>
						<td class="tdBranco">
							<h:outputText value="#{crudBean.entity.login}" />
						</td>
					</tr>
					<tr>
						<td class="tdCor" width="25%"><h:outputText value="#{bundle.lbl_ativo}"/></td>
						<td class="tdBranco"> 
							<h:outputText value="#{crudBean.entity.flagAtivo}" />
						</td>
					</tr>
				</table>
			</f:subview>
		</h:panelGroup>
		<!-- Painel de Visualizar - Fim -->
		
	</ui:define>
	
	<ui:define name="list">
		<h:panelGroup id="panelGroupDeListagem" rendered="#{crudBean.searching}">
			<f:subview id="viewListagem">
				<rich:dataTable id="tblData" value="#{crudBean.searchResult}" binding="#{crudBean.tblData}" var="rst" style="width: 100%;" rowClasses="par,impar">
               		
               		<rich:column style="text-align: left;" sortBy="#{rst.estEmpresaVo.descricao}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_empresa}" />
						</f:facet>
						<h:outputText value="#{rst.estEmpresaVo.descricao}"/>
					</rich:column>
               		<rich:column style="text-align: right;" sortBy="#{rst.codigo}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_codigo}" />
						</f:facet>
						<h:outputText value="#{rst.codigo}"/>
					</rich:column>
               		<rich:column style="text-align: left;" sortBy="#{rst.nome}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_nome}" />
						</f:facet>
						<h:outputText value="#{rst.nome}"/>
					</rich:column>
               		<rich:column style="text-align: left;" sortBy="#{rst.login}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_login}" />
						</f:facet>
						<h:outputText value="#{rst.login}"/>
					</rich:column>
               		<rich:column style="text-align: center;" sortBy="#{rst.flagAtivo}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_ativo}" />
						</f:facet>
						<h:outputText value="#{rst.flagAtivo}"/>
					</rich:column>
               		<rich:column style="text-align: center;">
						<f:facet name="header">
							<h:outputText value="" />
						</f:facet>
						<a4j:commandLink actionListener="#{crudBean.exibirSelecionado}" ajaxSingle="true" reRender="formulario, panelTitle">
							<h:graphicImage title="visualizar" value="/imagens/lupa.jpg" style="border: 0px;"/>
						</a4j:commandLink>
					</rich:column>
               		<rich:column style="text-align: center;">
						<f:facet name="header">
							<h:outputText value="" />
						</f:facet>
						<a4j:commandLink actionListener="#{crudBean.preparaAlterar}" ajaxSingle="true" reRender="formulario, panelTitle">
							<h:graphicImage title="alterar" value="/imagens/alterar.gif" style="border: 0px;"/>
						</a4j:commandLink>
					</rich:column>
				</rich:dataTable>
			</f:subview>
		</h:panelGroup>

		<h:panelGroup id="panelGroupDeVisualizar" rendered="#{crudBean.viewing}">
			<f:subview id="viewListVisualizar">
				<rich:dataTable value="#{crudBean.entity.filtroVo.listaExtensaoUsuario}" var="rst" style="width: 50%;" rowClasses="par,impar">
               		
               		<rich:column style="text-align: left;" sortBy="#{rst.codigo}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_codigo}" />
						</f:facet>
						<h:outputText value="#{rst.codigo}"/>
					</rich:column>
               		<rich:column style="text-align: left;" sortBy="#{rst.estLojaVo.codigo}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_codigo_loja}" />
						</f:facet>
						<h:outputText value="#{rst.estLojaVo.codigo}"/>
					</rich:column>
               		<rich:column style="text-align: left;" sortBy="#{rst.estLojaVo.descricao}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_loja}" />
						</f:facet>
						<h:outputText value="#{rst.estLojaVo.descricao}"/>
					</rich:column>
               		<rich:column style="text-align: center;" sortBy="#{rst.flagAtivo}">
						<f:facet name="header">
							<h:outputText value="#{bundle.lbl_ativo}" />
						</f:facet>
						<h:outputText value="#{rst.flagAtivo}"/>
					</rich:column>
				</rich:dataTable>
			</f:subview>
		</h:panelGroup>
	</ui:define>
	
</ui:composition>